{
 "metadata": {
  "signature": "sha256:59057bbce0ed692e3a7b59e80e33247182a2a9ae009293c7efadda91c984b5cc"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "Mayavi: examples\n",
      "======================================================================\n",
      "\n",
      "||\\<\\#80FF80\\> This page presents scripting Mayavi2 using the advanced,\n",
      "object-oriented API. Mayavi2 has recently acquired an easy-to-use,\n",
      "thought maybe not as powerful, scripting module: mlab. You are invited\n",
      "to refer to the\n",
      "[section](http://enthought.github.com/mayavi/mayavi/mlab.html) of\n",
      "[Mayavi2 user guide](http://enthought.github.com/mayavi/mayavi). ||\n",
      "\n",
      "Introduction\n",
      "------------\n",
      "\n",
      "Here, you will be presented some examples of rendering scenes you can\n",
      "get with !MayaVi2. You are advised to read\n",
      "[:Cookbook/MayaVi/ScriptingMayavi2] to understand what you see, although\n",
      "most examples given here are self-explanatory.\n",
      "\n",
      "||\\<\\#FF8080\\> Please note that these examples are not up to date. The\n",
      "example gallery for the latest version of Mayavi can be found at\n",
      "<http://enthought.github.com/mayavi/mayavi/auto/examples.html>. ||\n",
      "\n",
      "Example using IsoSurface Module (contour.py)\n",
      "--------------------------------------------"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#!/usr/bin/env mayavi2\n",
      "\n",
      "\"\"\"This script demonstrates how one can script MayaVi and use its\n",
      "contour related modules.  Notice the magic line at the top.\n",
      "\"\"\"\n",
      "# Author: Prabhu Ramachandran <prabhu_r@users.sf.net>\n",
      "# Copyright (c) 2005-2007, Enthought, Inc.\n",
      "# License: BSD Style.\n",
      "\n",
      "# Standard library imports\n",
      "from os.path import join, dirname\n",
      "\n",
      "# Enthought library imports\n",
      "import enthought.mayavi\n",
      "from enthought.mayavi.sources.vtk_file_reader import VTKFileReader\n",
      "from enthought.mayavi.filters.threshold import Threshold\n",
      "from enthought.mayavi.modules.outline import Outline\n",
      "from enthought.mayavi.modules.grid_plane import GridPlane\n",
      "from enthought.mayavi.modules.contour_grid_plane import ContourGridPlane\n",
      "from enthought.mayavi.modules.iso_surface import IsoSurface\n",
      "from enthought.mayavi.modules.scalar_cut_plane import ScalarCutPlane\n",
      "\n",
      "\n",
      "def contour():\n",
      "    \"\"\"The script itself.  We needn't have defined a function but\n",
      "    having a function makes this more reusable.\n",
      "    \"\"\"\n",
      "    # 'mayavi' is always defined on the interpreter.\n",
      "    # Create a new scene.\n",
      "    mayavi.new_scene()\n",
      "\n",
      "    # Read a VTK (old style) data file.\n",
      "    r = VTKFileReader()\n",
      "    r.initialize(join(dirname(enthought.mayavi.__file__),\n",
      "                      'examples', 'data', 'heart.vtk'))\n",
      "    mayavi.add_source(r)\n",
      "\n",
      "    # Create an outline for the data.\n",
      "    o = Outline()\n",
      "    mayavi.add_module(o)\n",
      "\n",
      "    # Create three simple grid plane modules.\n",
      "    # First normal to 'x' axis.\n",
      "    gp = GridPlane()\n",
      "    mayavi.add_module(gp)\n",
      "    # Second normal to 'y' axis.\n",
      "    gp = GridPlane()\n",
      "    mayavi.add_module(gp)\n",
      "    gp.grid_plane.axis = 'y'\n",
      "    # Third normal to 'z' axis.\n",
      "    gp = GridPlane()\n",
      "    mayavi.add_module(gp)\n",
      "    gp.grid_plane.axis = 'z'\n",
      "\n",
      "    # Create one ContourGridPlane normal to the 'x' axis.\n",
      "    cgp = ContourGridPlane()\n",
      "    mayavi.add_module(cgp)\n",
      "    # Set the position to the middle of the data.\n",
      "    cgp.grid_plane.position = 15\n",
      "\n",
      "    # Another with filled contours normal to 'y' axis.\n",
      "    cgp = ContourGridPlane()\n",
      "    mayavi.add_module(cgp)\n",
      "    # Set the axis and position to the middle of the data.\n",
      "    cgp.grid_plane.axis = 'y'\n",
      "    cgp.grid_plane.position = 15\n",
      "    cgp.contour.filled_contours = True\n",
      "\n",
      "    # An isosurface module.\n",
      "    iso = IsoSurface(compute_normals=True)\n",
      "    mayavi.add_module(iso)\n",
      "    iso.contour.contours = [220.0]\n",
      "\n",
      "    # An interactive scalar cut plane.\n",
      "    cp = ScalarCutPlane()\n",
      "    mayavi.add_module(cp)\n",
      "    cp.implicit_plane.normal = 0,0,1\n",
      "    \n",
      "\n",
      "if __name__ == '__main__':\n",
      "    contour()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "![](files/attachments/MayaVi_examples/contour.png)\n",
      "\n",
      "Example using Glyph Module (glyph.py)\n",
      "-------------------------------------"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#!/usr/bin/env mayavi2\n",
      "\n",
      "\"\"\"This script demonstrates the use of a VectorCutPlane, splitting the\n",
      "pipeline using a MaskPoints filter and then viewing the filtered data\n",
      "with the Glyph module.\n",
      "\"\"\"\n",
      "# Author: Prabhu Ramachandran <prabhu_r@users.sf.net>\n",
      "# Copyright (c) 2005-2007, Enthought, Inc.\n",
      "# License: BSD Style.\n",
      "\n",
      "# Standard library imports\n",
      "from os.path import join, dirname\n",
      "\n",
      "# Enthought library imports\n",
      "import enthought.mayavi\n",
      "from enthought.mayavi.sources.vtk_xml_file_reader import VTKXMLFileReader\n",
      "from enthought.mayavi.modules.outline import Outline\n",
      "from enthought.mayavi.modules.glyph import Glyph\n",
      "from enthought.mayavi.modules.vector_cut_plane import VectorCutPlane\n",
      "from enthought.mayavi.modules.vectors import Vectors\n",
      "from enthought.mayavi.filters.mask_points import MaskPoints\n",
      "\n",
      "\n",
      "def glyph():\n",
      "    \"\"\"The script itself.  We needn't have defined a function but\n",
      "    having a function makes this more reusable.\n",
      "    \"\"\"\n",
      "    # 'mayavi' is always defined on the interpreter.\n",
      "    # Create a new VTK scene.\n",
      "    mayavi.new_scene()\n",
      "\n",
      "    # Read a VTK (old style) data file.\n",
      "    r = VTKXMLFileReader()\n",
      "    r.initialize(join(dirname(enthought.mayavi.__file__),\n",
      "                      'examples', 'data', 'fire_ug.vtu'))\n",
      "    mayavi.add_source(r)\n",
      "\n",
      "    # Create an outline and a vector cut plane.\n",
      "    mayavi.add_module(Outline())\n",
      "\n",
      "    v = VectorCutPlane()\n",
      "    mayavi.add_module(v)\n",
      "    v.glyph.color_mode = 'color_by_scalar'\n",
      "\n",
      "    # Now mask the points and show glyphs (we could also use\n",
      "    # Vectors but glyphs are a bit more generic)\n",
      "    m = MaskPoints()\n",
      "    m.filter.set(on_ratio=10, random_mode=True)\n",
      "    mayavi.add_filter(m)\n",
      "\n",
      "    g = Glyph()\n",
      "    mayavi.add_module(g)\n",
      "    # Note that this adds the module to the filtered output.\n",
      "    g.glyph.scale_mode = 'scale_by_vector'\n",
      "    # Use arrows to view the scalars.\n",
      "    g.glyph.glyph_source = g.glyph.glyph_list[1]\n",
      "\n",
      "\n",
      "if __name__ == '__main__':\n",
      "    glyph()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "![](files/attachments/MayaVi_examples/glyph.png)\n",
      "\n",
      "Example without Mayavi2 UI (nongui.py)\n",
      "--------------------------------------"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#!/usr/bin/env python\n",
      "\n",
      "\"\"\"This script demonstrates how one can use the MayaVi framework\n",
      "without displaying MayaVi's UI.  Note: look at the end of this file to\n",
      "see how the non gui plugin is chosen instead of the default gui\n",
      "mayavi plugin.\n",
      "\n",
      "\"\"\"\n",
      "# Author: Prabhu Ramachandran <prabhu_r@users.sf.net>\n",
      "# Copyright (c) 2005, Enthought, Inc.\n",
      "# License: BSD Style.\n",
      "\n",
      "# On systems with multiple wx installations installed, pick one that works\n",
      "# with the libraries Mayavi depends on.\n",
      "try:\n",
      "    import wxversion\n",
      "    wxversion.ensureMinimal('2.6')\n",
      "except ImportError:\n",
      "    pass\n",
      "\n",
      "# Standard library imports\n",
      "import sys\n",
      "from os.path import join, dirname\n",
      "\n",
      "# Enthought library imports\n",
      "from enthought.mayavi.app import Mayavi, NONGUI_PLUGIN_DEFINITIONS\n",
      "\n",
      "\n",
      "class MyApp(Mayavi):\n",
      "    def run(self):\n",
      "        \"\"\"This is executed once the application GUI has started.\n",
      "        *Make sure all other MayaVi specific imports are made here!*\n",
      "        \"\"\"\n",
      "\n",
      "        # Various imports to do different things.\n",
      "        from enthought.mayavi.sources.vtk_file_reader import VTKFileReader\n",
      "        from enthought.mayavi.modules.outline import Outline\n",
      "        from enthought.mayavi.modules.axes import Axes\n",
      "        from enthought.mayavi.modules.grid_plane import GridPlane\n",
      "        from enthought.mayavi.modules.image_plane_widget import ImagePlaneWidget\n",
      "        from enthought.mayavi.modules.text import Text\n",
      "        from enthought.mayavi.modules.contour_grid_plane import ContourGridPlane\n",
      "        from enthought.mayavi.modules.iso_surface import IsoSurface\n",
      "\n",
      "        script = self.script\n",
      "\n",
      "        # Create a new scene.\n",
      "        script.new_scene()\n",
      "\n",
      "        # Read a VTK (old style) data file.\n",
      "        r = VTKFileReader()\n",
      "        r.initialize('data/heart.vtk')\n",
      "        r.initialize(join(dirname(__file__), 'data', 'heart.vtk'))\n",
      "        script.add_source(r)\n",
      "\n",
      "        # Put up some text.\n",
      "        t = Text(text='MayaVi rules!', x_position=0.2, y_position=0.9, width=0.8)\n",
      "        t.property.color = 1, 1, 0  # Bright yellow, yeah!\n",
      "        script.add_module(t)\n",
      "\n",
      "        # Create an outline for the data.\n",
      "        o = Outline()\n",
      "        script.add_module(o)\n",
      "\n",
      "        # Create an axes for the data.\n",
      "        a = Axes()\n",
      "        script.add_module(a)\n",
      "\n",
      "        # Create three simple grid plane modules.\n",
      "        # First normal to 'x' axis.\n",
      "        gp = GridPlane()\n",
      "        script.add_module(gp)\n",
      "        # Second normal to 'y' axis.\n",
      "        gp = GridPlane()\n",
      "        gp.grid_plane.axis = 'y'\n",
      "        script.add_module(gp)\n",
      "        # Third normal to 'z' axis.\n",
      "        gp = GridPlane()\n",
      "        script.add_module(gp)\n",
      "        gp.grid_plane.axis = 'z'\n",
      "\n",
      "        # Create one ImagePlaneWidget.\n",
      "        ipw = ImagePlaneWidget()\n",
      "        script.add_module(ipw)\n",
      "        # Set the position to the middle of the data.\n",
      "        ipw.ipw.slice_position = 16\n",
      "\n",
      "        # Create one ContourGridPlane normal to the 'x' axis.\n",
      "        cgp = ContourGridPlane()\n",
      "        script.add_module(cgp)\n",
      "        # Set the position to the middle of the data.\n",
      "        cgp.grid_plane.axis = 'y'\n",
      "        cgp.grid_plane.position = 15\n",
      "\n",
      "        # An isosurface module.\n",
      "        iso = IsoSurface(compute_normals=True)\n",
      "        script.add_module(iso)\n",
      "        iso.contour.contours = [200.0]    \n",
      "\n",
      "        # Set the view.\n",
      "        s = script.engine.current_scene\n",
      "        cam = s.scene.camera\n",
      "        cam.azimuth(45)\n",
      "        cam.elevation(15)\n",
      "        s.render()\n",
      "    \n",
      "    \n",
      "if __name__ == '__main__':\n",
      "    m = MyApp()\n",
      "    # Note how we change the plugins that are loaded only here.\n",
      "    m.main(plugin_defs=NONGUI_PLUGIN_DEFINITIONS)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "![](files/attachments/MayaVi_examples/nongui.png)\n",
      "\n",
      "Example with a 3D array as numerical source (numeric\\_source.py)\n",
      "----------------------------------------------------------------"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#!/usr/bin/env mayavi2\n",
      "\n",
      "\"\"\"This script demonstrates how to create a numpy array data and\n",
      "visualize it as image data using a few modules.\n",
      "\n",
      "\"\"\"\n",
      "# Author: Prabhu Ramachandran <prabhu_r@users.sf.net>\n",
      "# Copyright (c) 2005-2007, Enthought, Inc.\n",
      "# License: BSD Style.\n",
      "\n",
      "# Standard library imports\n",
      "import enthought.util.scipyx as scipy\n",
      "\n",
      "# Enthought library imports\n",
      "from enthought.mayavi.sources.array_source import ArraySource\n",
      "from enthought.mayavi.modules.outline import Outline\n",
      "from enthought.mayavi.modules.image_plane_widget import ImagePlaneWidget\n",
      "\n",
      "\n",
      "def make_data(dims=(128, 128, 128)):\n",
      "    \"\"\"Creates some simple array data of the given dimensions to test\n",
      "    with.\"\"\"\n",
      "    np = dims[0]*dims[1]*dims[2]\n",
      "\n",
      "    # Create some scalars to render.\n",
      "    x, y, z = scipy.ogrid[-5:5:dims[0]*1j,-5:5:dims[1]*1j,-5:5:dims[2]*1j]\n",
      "    x = x.astype('f')\n",
      "    y = y.astype('f')\n",
      "    z = z.astype('f')\n",
      "\n",
      "    scalars = (scipy.sin(x*y*z)/(x*y*z))\n",
      "    return scipy.transpose(scalars).copy() # This makes the data contiguous.\n",
      "\n",
      "\n",
      "def view_numpy():\n",
      "    \"\"\"Example showing how to view a 3D numpy array in mayavi2.\n",
      "    \"\"\"\n",
      "    # 'mayavi' is always defined on the interpreter.\n",
      "    mayavi.new_scene()\n",
      "    # Make the data and add it to the pipeline.\n",
      "    data = make_data()\n",
      "    src = ArraySource(transpose_input_array=False)\n",
      "    src.scalar_data = data    \n",
      "    mayavi.add_source(src)\n",
      "    # Visualize the data.\n",
      "    o = Outline()\n",
      "    mayavi.add_module(o)\n",
      "    ipw = ImagePlaneWidget()\n",
      "    mayavi.add_module(ipw)\n",
      "    ipw.module_manager.scalar_lut_manager.show_scalar_bar = True\n",
      "\n",
      "    ipw_y = ImagePlaneWidget()\n",
      "    mayavi.add_module(ipw_y)\n",
      "    ipw_y.ipw.plane_orientation = 'y_axes'\n",
      "\n",
      "    \n",
      "if __name__ == '__main__':\n",
      "    view_numpy()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "![](files/attachments/MayaVi_examples/numeric_source.png)\n",
      "\n",
      "Example using Streamline Module (streamline.py)\n",
      "-----------------------------------------------"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#!/usr/bin/env mayavi2\n",
      "\"\"\"This script demonstrates how one can script MayaVi to display\n",
      "streamlines and an iso surface.\n",
      "\"\"\"\n",
      "# Author: Prabhu Ramachandran <prabhu_r@users.sf.net>\n",
      "# Copyright (c) 2005-2007, Enthought, Inc.\n",
      "# License: BSD Style.\n",
      "\n",
      "# Standard library imports\n",
      "from os.path import join, dirname\n",
      "\n",
      "# Enthought library imports\n",
      "from enthought.mayavi.sources.vtk_xml_file_reader import VTKXMLFileReader\n",
      "from enthought.mayavi.modules.outline import Outline\n",
      "from enthought.mayavi.modules.streamline import Streamline\n",
      "from enthought.mayavi.modules.iso_surface import IsoSurface\n",
      "\n",
      "\n",
      "def setup_data(fname):\n",
      "    \"\"\"Given a VTK XML file name `fname`, this creates a mayavi2\n",
      "    reader for it and adds it to the pipeline.  It returns the reader\n",
      "    created.\n",
      "    \"\"\"\n",
      "    mayavi.new_scene()\n",
      "    r = VTKXMLFileReader()\n",
      "    r.initialize(fname)\n",
      "    mayavi.add_source(r)\n",
      "    return r\n",
      "\n",
      "def streamline():\n",
      "    \"\"\"Sets up the mayavi pipeline for the visualization.\n",
      "    \"\"\"\n",
      "    # Create an outline for the data.\n",
      "    o = Outline()\n",
      "    mayavi.add_module(o)\n",
      "\n",
      "    s = Streamline(streamline_type='tube')\n",
      "    mayavi.add_module(s)\n",
      "    s.stream_tracer.integration_direction = 'both'\n",
      "    s.seed.widget.center = 3.5, 0.625, 1.25\n",
      "    s.module_manager.scalar_lut_manager.show_scalar_bar = True\n",
      "\n",
      "    i = IsoSurface()\n",
      "    mayavi.add_module(i)\n",
      "    i.contour.contours[0] = 550\n",
      "    i.actor.property.opacity = 0.5\n",
      "\n",
      "\n",
      "if __name__ == '__main__':\n",
      "    import enthought.mayavi\n",
      "    fname = join(dirname(enthought.mayavi.__file__),\n",
      "                 'examples', 'data', 'fire_ug.vtu')\n",
      "    r = setup_data(fname)\n",
      "    streamline()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "![](files/attachments/MayaVi_examples/streamline.png)\n",
      "\n",
      "Example using ImagePlaneWidget Module (test.py)\n",
      "-----------------------------------------------"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#!/usr/bin/env python\n",
      "\n",
      "\"\"\"This script demonstrates how one can script MayaVi, set its size,\n",
      "create a new VTK scene and create a few simple modules.\n",
      "\n",
      "\"\"\"\n",
      "# Author: Prabhu Ramachandran <prabhu_r@users.sf.net>\n",
      "# Copyright (c) 2005, Enthought, Inc.\n",
      "# License: BSD Style.\n",
      "\n",
      "# On systems with multiple wx installations installed, pick one that works\n",
      "# with the libraries Mayavi depends on.\n",
      "try:\n",
      "    import wxversion\n",
      "    wxversion.ensureMinimal('2.6')\n",
      "except ImportError:\n",
      "    pass\n",
      "\n",
      "# Standard library imports\n",
      "import sys\n",
      "from os.path import join, dirname\n",
      "\n",
      "# Enthought library imports\n",
      "from enthought.mayavi.app import Mayavi\n",
      "\n",
      "\n",
      "class MyApp(Mayavi):\n",
      "    def run(self):\n",
      "        \"\"\"This is executed once the application GUI has started.\n",
      "        *Make sure all other MayaVi specific imports are made here!*\n",
      "        \"\"\"\n",
      "        # Various imports to do different things.\n",
      "        from enthought.mayavi.sources.vtk_file_reader import VTKFileReader\n",
      "        from enthought.mayavi.filters.threshold import Threshold\n",
      "        from enthought.mayavi.modules.outline import Outline\n",
      "        from enthought.mayavi.modules.axes import Axes\n",
      "        from enthought.mayavi.modules.grid_plane import GridPlane\n",
      "        from enthought.mayavi.modules.image_plane_widget import ImagePlaneWidget\n",
      "        from enthought.mayavi.modules.text import Text\n",
      "\n",
      "        script = self.script\n",
      "        # Create a new scene.\n",
      "        script.new_scene()\n",
      "\n",
      "        # Read a VTK (old style) data file.\n",
      "        r = VTKFileReader()\n",
      "        r.initialize(join(dirname(__file__), 'data', 'heart.vtk'))\n",
      "        script.add_source(r)\n",
      "\n",
      "        # Put up some text.\n",
      "        t = Text(text='MayaVi rules!', x_position=0.2,\n",
      "                 y_position=0.9, width=0.8)\n",
      "        t.property.color = 1, 1, 0  # Bright yellow, yeah!\n",
      "        script.add_module(t)\n",
      "\n",
      "        # Create an outline for the data.\n",
      "        o = Outline()\n",
      "        script.add_module(o)\n",
      "\n",
      "        # Create an axes for the data.\n",
      "        a = Axes()\n",
      "        script.add_module(a)\n",
      "\n",
      "        # Create an orientation axes for the scene.  This only works with\n",
      "        # VTK-4.5 and above which is why we have the try block.\n",
      "        try:\n",
      "            from enthought.mayavi.modules.orientation_axes import OrientationAxes\n",
      "        except ImportError:\n",
      "            pass\n",
      "        else:\n",
      "            a = OrientationAxes()\n",
      "            a.marker.set_viewport(0.0, 0.8, 0.2, 1.0)\n",
      "            script.add_module(a)\n",
      "\n",
      "        # Create three simple grid plane modules.\n",
      "        # First normal to 'x' axis.\n",
      "        gp = GridPlane()\n",
      "        script.add_module(gp)\n",
      "        # Second normal to 'y' axis.\n",
      "        gp = GridPlane()\n",
      "        gp.grid_plane.axis = 'y'\n",
      "        script.add_module(gp)\n",
      "        # Third normal to 'z' axis.\n",
      "        gp = GridPlane()\n",
      "        script.add_module(gp)\n",
      "        gp.grid_plane.axis = 'z'\n",
      "\n",
      "        # Create one ImagePlaneWidget.\n",
      "        ipw = ImagePlaneWidget()\n",
      "        script.add_module(ipw)\n",
      "        # Set the position to the middle of the data.\n",
      "        ipw.ipw.slice_position = 16\n",
      "\n",
      "    \n",
      "\n",
      "if __name__ == '__main__':\n",
      "    a = MyApp()\n",
      "    a.main()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "![](files/attachments/MayaVi_examples/test.png)\n",
      "\n",
      "Example using mlab (surf\\_regular\\_mlab.py)\n",
      "-------------------------------------------\n",
      "\n",
      "See also [:Cookbook/MayaVi/Surf] for another way of doing this."
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#!/usr/bin/env mayavi2\n",
      "\"\"\"Shows how to view data created by `enthought.tvtk.tools.mlab` with\n",
      "mayavi2.\n",
      "\"\"\"\n",
      "\n",
      "# Author: Prabhu Ramachandran <prabhu@aero.iitb.ac.in>\n",
      "# Copyright (c) 2006-2007, Enthought Inc.\n",
      "# License: BSD Style.\n",
      "\n",
      "import numpy\n",
      "\n",
      "from enthought.tvtk.tools import mlab\n",
      "from enthought.mayavi.sources.vtk_data_source import VTKDataSource\n",
      "from enthought.mayavi.filters.warp_scalar import WarpScalar\n",
      "from enthought.mayavi.modules.outline import Outline\n",
      "from enthought.mayavi.modules.surface import Surface\n",
      "\n",
      "\n",
      "def f(x, y):\n",
      "    \"\"\"Some test function.\n",
      "    \"\"\"\n",
      "    return numpy.sin(x*y)/(x*y)\n",
      "\n",
      "def make_data():\n",
      "    \"\"\"Make some test numpy data and create a TVTK data object from it\n",
      "    that we will visualize.\n",
      "    \"\"\"    \n",
      "    x = numpy.arange(-7., 7.05, 0.1)\n",
      "    y = numpy.arange(-5., 5.05, 0.05)\n",
      "    s = mlab.SurfRegular(x, y, f)\n",
      "    return s.data\n",
      "\n",
      "def add_data(tvtk_data):\n",
      "    \"\"\"Add a TVTK data object `tvtk_data` to the mayavi pipleine.\n",
      "    \"\"\"\n",
      "    d = VTKDataSource()\n",
      "    d.data = tvtk_data\n",
      "    mayavi.add_source(d)\n",
      "\n",
      "def surf_regular():\n",
      "    \"\"\"Now visualize the data as done in mlab.\n",
      "    \"\"\"\n",
      "    w = WarpScalar()\n",
      "    mayavi.add_filter(w)\n",
      "    o = Outline()\n",
      "    s = Surface()\n",
      "    mayavi.add_module(o)\n",
      "    mayavi.add_module(s)\n",
      "\n",
      "\n",
      "if __name__ == '__main__':\n",
      "    mayavi.new_scene()\n",
      "    d = make_data()\n",
      "    add_data(d)\n",
      "    surf_regular()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    }
   ],
   "metadata": {}
  }
 ]
}